<template>
  <div class="topBox">
    <div class="L"><a href="index.html">LOGO</a></div>
    <div class="C">
      <van-cell-group inset>
        <van-field
          v-model="proName"
          @change="search"
          placeholder="请输入您要搜索的内容"
          src="/assets/images/ss.png"
        />
      </van-cell-group>
    </div>

    <div class="R"><img src="/assets/images/tr.png" /></div>
  </div>
  <div class="clear"></div>
  <div class="aui-m-slider">
    <van-swipe
      class="my-swipe"
      height="210"
      :autoplay="3000"
      indicator-color="white"
    >
      <template v-for="item in proList" :key="item.id">
        <van-swipe-item v-if="item.flag == 3">
          <router-link
            :to="{ path: '/product/product/info', query: { proid: item.id } }"
          >
            <img :src="item.cover_cdn" style="width: 100%; height: 100%" />
          </router-link>
        </van-swipe-item>
      </template>
    </van-swipe>
  </div>
  <div class="clear"></div>
  <div class="lqgwBox">
    <ul>
      <li v-for="item in typeList" :key="item.id">
        <router-link
          :to="{ path: '/product/product/index', query: { typeid: item.id } }"
        >
          <img :src="item.cover_cdn" />
          <p>{{ item.name }}</p>
        </router-link>
      </li>
    </ul>
  </div>
  <div class="clear"></div>

  <div class="clear"></div>
  <div class="contitbox">
    <p>新品</p>
  </div>
  <div class="clear"></div>
  <ul class="proul">
    <template v-for="item in proList" :key="item.id">
      <li v-if="item.flag == 1">
        <div class="con">
          <router-link
            :to="{ path: '/product/product/info', query: { proid: item.id } }"
          >
            <img :src="item.cover_cdn" />
            <p><span>￥</span>{{ item.price }}</p>
          </router-link>
        </div>
      </li>
    </template>
  </ul>
  <div class="clear"></div>

  <div class="contitbox">
    <p>热销</p>
  </div>
  <div class="clear"></div>
  <ul class="proul_2">
    <template v-for="item in proList" :key="item.id">
      <li v-if="item.flag == 2">
        <div class="con">
          <router-link
            :to="{ path: '/product/product/info', query: { proid: item.id } }"
          >
            <img :src="item.cover_cdn" />
            <p><span>￥</span>{{ item.price }}</p>
          </router-link>
        </div>
      </li>
    </template>
  </ul>
  <div class="clear"></div>
  <div class="h54"></div>
  <div class="clear"></div>
  <Tab />
</template>
<script>
import Tab from "components/common/Tab.vue";
import { showFailToast } from "vant";

export default {
  components: {
    Tab,
  },
  data() {
    return {
      proList: [],
      typeList: [],
    };
  },
  created() {
    this.getHomeData();
    // console.log(this.proList);
  },
  methods: {
    async getHomeData() {
      let result = await this.$api.home();
      // console.log(result);

      if (result.code === 1) {
        this.proList = result.data.proList;

        this.typeList = result.data.typeList;
      }
    },
    async search() {
      // console.log(data);
      this.$router.push({
        path: "product/product/search",
        query: {
          keywords: this.proName,
        },
      });
      // let result = await this.$api.ProductIndex(data);
      // // console.log(result);

      // if (result.code === 1 && result.data.length != 0) {

      // } else {
      //   showFailToast("暂无该商品");
      // }

      // console.log(result);

      // this.getTypeData(data);
    },
  },
};
</script>